package com.launch.carmanager.common.utils;


import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.view.MenuItem;

import com.launch.carmanager.BuildConfig;

public final class DrawableUtils {

    private DrawableUtils() {
        // hide constructor
    }

    public static Drawable setTint(Context context, @DrawableRes int drawableResID, @ColorRes int colorResID) {
        return setTint(context, ResourceUtils.getDrawable(context, drawableResID), colorResID);
    }

    public static Drawable setTint(Context context, Drawable drawable, @ColorRes int colorResID) {
        Drawable d = DrawableCompat.wrap(drawable).mutate();
        DrawableCompat.setTint(d, ResourceUtils.getColor(context, colorResID));
        return d;
    }

    public static void setTint(Context context, MenuItem item, @ColorRes int colorResID) {
        final Drawable drawable = item.getIcon();
        if (drawable != null) {
            item.setIcon(setTint(context, drawable, colorResID));
        }
    }

    public static Drawable setTintList(Context context, Drawable drawable, @ColorRes int colorResID) {
        return setTintList(drawable, ResourceUtils.getColorStateList(context, colorResID));
    }

    public static Drawable setTintList(Context context, @DrawableRes int drawableResID, @ColorRes int colorResID) {
        return setTintList(context, ResourceUtils.getDrawable(context, drawableResID), colorResID);
    }

    public static Drawable setTintList(Context context, @DrawableRes int drawableResID, ColorStateList colorStateList) {
        return setTintList(ResourceUtils.getDrawable(context, drawableResID), colorStateList);
    }

    public static Drawable setTintList(Drawable drawable, ColorStateList colorStateList) {
        Drawable d = DrawableCompat.wrap(drawable).mutate();
        DrawableCompat.setTintList(d, colorStateList);
        return d;
    }

    public static String getDrawablePath(@DrawableRes int drawableResID) {
        return "android.resource://" + BuildConfig.APPLICATION_ID + "/drawable/" + drawableResID;
    }


}
